local shizhong = fk.CreateSkill{
  name = "swis__shizhong",
}

Fk:loadTranslationTable{
  ["swis__shizhong"] = "恃众",
  [":swis__shizhong"] = "出牌阶段限一次，你可以视为对所有手牌数小于你的角色使用一张【万箭齐发】。"
  .."当一名角色响应此牌后，其可以令你摸或弃一张牌。",

  ["#swis__shizhong-prompt"] = "恃众：可以视为对所有手牌数小于你的角色使用一张【万箭齐发】",
  ["swis__shizhong_draw"] = "令 %src 摸一张牌",
  ["swis__shizhong_discard"] = "令 %src 弃一张牌",
}

shizhong:addEffect("active",{
  anim_type = "offensive",
  prompt = "#swis__shizhong-prompt",
  can_use = function (self, player)
    if player:usedSkillTimes(shizhong.name) == 0 then
      local card = Fk:cloneCard("archery_attack")
      card.skillName = shizhong.name
      return #table.filter(Fk:currentRoom().alive_players, function (p)
        return #p:getCardIds("h") < #player:getCardIds("h") and player:canUseTo(card, p)
      end) > 0
    end
  end,
  card_num = 0,
  target_num = 0,
  card_filter = Util.FalseFunc,
  target_filter = Util.FalseFunc,
  on_use = function (self, room, effect)
    local card = Fk:cloneCard("archery_attack")
    card.skillName = shizhong.name
    local player = effect.from
    local targets = table.filter(room:getAlivePlayers(false), function (p)
      return p:getHandcardNum() < player:getHandcardNum() and player:canUseTo(card, p)
    end)
    if #targets == 0 then return end
    room:useCard{
      from = player,
      tos = targets,
      card = card,
    }
  end,
})

shizhong:addEffect(fk.CardResponding, {
  anim_type = "support",
  can_trigger = function (self, event, target, player, data)
    local e = data.responseToEvent
    if e and e.from == player and e.card.skillName == shizhong.name then
      return true
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local choices = {"swis__shizhong_draw:"..player.id, "swis__shizhong_discard:"..player.id, "Cancel"}
    local choice = room:askToChoice(target, {
      choices = choices,
      all_choices = choices,
      cancelable = true,
      detailed = false,
      skill_name = shizhong.name,
    })
    if choice then
      event:setCostData(self, table.indexOf(choices, choice))
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local index = event:getCostData(self)
    if index == 1 then
      player:drawCards(1, shizhong.name)
    else
      room:askToDiscard(player, {
        min_num = 1,
        max_num = 1,
        skill_name = shizhong.name,
      })
    end
  end
})

return shizhong